﻿Imports XL.Common
Imports XL.Common.Utils
Imports System.Collections
Imports System.Data

Namespace Facade

    Public Class OpBizManage

        Public Shared Sub FillClientPersonRowSEntityByCallNumber( _
            ByVal callNumber As String, _
            ByRef clientRowSE As RExpXAuto.FTs.FT_M_REXP_CLIENTRowSEntity, _
            ByRef clientPersonRowSE As RExpXAuto.FTs.FT_M_REXP_CLIENT_PERSONRowSEntity)

            Dim clientPersonCondition As New RExpXAuto.Facade.AfBizMaster.ConditionOfM_REXP_CLIENT_PERSON(XL.DB.Utils.Condition.LogicOperators.Logic_Or)
            clientPersonCondition.Add(RExpXAuto.Facade.AfBizMaster.M_REXP_CLIENT_PERSONColumns.TEL1Column, "=", callNumber)
            clientPersonCondition.Add(RExpXAuto.Facade.AfBizMaster.M_REXP_CLIENT_PERSONColumns.TEL2Column, "=", callNumber)
            clientPersonCondition.Add(RExpXAuto.Facade.AfBizMaster.M_REXP_CLIENT_PERSONColumns.TEL3Column, "=", callNumber)

            RExpXAuto.Facade.AfBizMaster.FillM_REXP_CLIENT_PERSONRowSEntity(clientPersonRowSE, clientPersonCondition)

            Dim clientCondition As New RExpXAuto.Facade.AfBizMaster.ConditionOfM_REXP_CLIENT(XL.DB.Utils.Condition.LogicOperators.Logic_And)
            If clientPersonRowSE.IsNull = False Then
                clientCondition.Add(RExpXAuto.Facade.AfBizMaster.M_REXP_CLIENTColumns.CLIENT_IDColumn, "=", clientPersonRowSE.CLIENT_ID)
            Else
                clientCondition.Add(RExpXAuto.Facade.AfBizMaster.M_REXP_CLIENTColumns.WORK_PHONEColumn, "=", callNumber)
            End If

            RExpXAuto.Facade.AfBizMaster.FillM_REXP_CLIENTRowSEntity(clientRowSE, clientCondition)

        End Sub

        Public Shared Sub FillCacheIncomingCallListAbsent(ByVal cacheIncomingCallList As RExpXAuto.FTs.FT_H_REXP_INCOMING_CALL)

            Dim clientRowSE As New RExpXAuto.FTs.FT_M_REXP_CLIENTRowSEntity
            Dim clientPersonRowSE As New RExpXAuto.FTs.FT_M_REXP_CLIENT_PERSONRowSEntity
            Dim informStaffRowSE As New RExpXAuto.FTs.FT_M_REXP_STAFFRowSEntity

            For Each callRow In cacheIncomingCallList.FindRowsUndeleted

                callRow.ROW_HIGHLIGHT = RExpXService.Decls.ROW_HIGHLIGHT_CACHE_ROW

                OpBizManage.FillClientPersonRowSEntityByCallNumber(callRow.CALL_PHONE_NO, clientRowSE, clientPersonRowSE)

                callRow.CLIENT_PERSON_NAME = clientPersonRowSE.PERSON_NAME
                callRow.CLIENT_ADDRESS = clientRowSE.WORK_ADDRESS
                callRow.CLIENT_NAME = clientRowSE.CLIENT_NAME
                callRow.CLIENT_ID = clientRowSE.CLIENT_ID

                RExpXAuto.Facade.AfBizMaster.FillM_REXP_STAFFRowSEntity(informStaffRowSE, clientRowSE.CONTACT_STAFF)

                callRow.INFORM_STAFF_ID = informStaffRowSE.STAFF_ID
                callRow.INFORM_STAFF_CODE = informStaffRowSE.STAFF_CODE
                callRow.INFORM_STAFF_NAME = informStaffRowSE.STAFF_NAME
                callRow.INFORM_STAFF_CELL_PHONE = informStaffRowSE.CELL_PHONE


            Next
        End Sub

    End Class

End Namespace

